#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "../../../NetEngine_Linux/NetEngine_SourceCode/XyRyNet_CommHdr.h"
#include "../../../NetEngine_Linux/NetEngine_SourceCode/XyRyNet_Types.h"
#include "../../../NetEngine_Linux/NetEngine_SourceCode/XyRyNet_ProtocolHdr.h"
#include "../../../NetEngine_Linux/NetEngine_SourceCode/NetEngine_Lib/NetEngine_BaseLib/BaseLib_Define.h"
#include "../../../NetEngine_Linux/NetEngine_SourceCode/NetEngine_NetHelp/NetHelp_APIHelp/APIHelp_Define.h"
#include "../../../NetEngine_Linux/NetEngine_SourceCode/NetEngine_NetHelp/NetHelp_APIHelp/APIHelp_Error.h"

//g++ -std=gnu++11 -Wall -g TestNetInfo.cpp -o TestNetInfo -L ../../../NetEngine_Linux/NetEngine_Release/NetEngine_Release/NetEngine_BaseLib -L ../../../NetEngine_Linux/NetEngine_Release/NetEngine_Release/NetEngine_NetHelp -lNetEngine_BaseLib -lNetHelp_APIHelp -Wl,-rpath=../../../NetEngine_Linux/NetEngine_Release/NetEngine_Release/NetEngine_BaseLib:../../../NetEngine_Linux/NetEngine_Release/NetEngine_Release/NetEngine_NetHelp,--disable-new-dtags

int Test_HttpRequest()
{
    //LPCTSTR lpszUrl = _T("http://192.168.2.209:5580/Api/BackService/GetTask");
    LPCTSTR lpszUrl = _T("http://192.168.4.31:9988/cmd/api/v1/messages/9003");
    int nResponse = 0;
    int nSourceLen = 102400;
    int nDestLen = 102400;

    TCHAR tszSourceBuffer[102400];
    TCHAR tszDestBuffer[102400];
    memset(tszSourceBuffer, '\0', sizeof(tszSourceBuffer));
    memset(tszDestBuffer, '\0', sizeof(tszDestBuffer));

    APIHelp_HttpRequest_Post(lpszUrl, &nResponse, NULL, tszSourceBuffer, &nSourceLen, NULL, NULL, _T("Content-Type: application/json\r\n"));
    //APIHelp_HttpRequest_Post(lpszUrl, tszSourceBuffer,&nResponse,"Accept-Encoding: gzip, deflate\r\n",NULL,&nSourceLen);
    //HelpCompress_Algorithm_GZipUnCompress((BYTE *)tszSourceBuffer, nSourceLen, (BYTE *)tszDestBuffer, (DWORD *)&nDestLen);
    printf("%s\n", tszSourceBuffer);
    return 0;
}
int Test_NetGetIPAddr()
{
    TCHAR tszLocalBuffer[1024];
    TCHAR tszRemoteBuffer[1024];
    memset(tszLocalBuffer, '\0', sizeof(tszLocalBuffer));
    memset(tszRemoteBuffer, '\0', sizeof(tszRemoteBuffer));

    APIHelp_NetWork_GetIPAddr(tszLocalBuffer, tszRemoteBuffer);
    printf("%s\n%s\n", tszLocalBuffer, tszRemoteBuffer);
    return 0;
}

void __stdcall NetHelp_HttpGet_Chunked(LPVOID lpszMsgBuffer, int nMsgLen, LPVOID lParam)
{
    printf("%d\n%s\n", nMsgLen, (LPCTSTR)lpszMsgBuffer);
}
int Test_HttpChunked()
{
    LPCTSTR lpszUrl = _T("http://192.168.4.37:9808/video?app=streamweb&stream=18215555151_1_1");

    XHANDLE pxhChunked = APIHelp_HttpRequest_ChunkedOPen(lpszUrl,NetHelp_HttpGet_Chunked);
    APIHelp_HttpRequest_ChunkedClose(pxhChunked);
    return 0;
}

int main()
{
    Test_HttpChunked();
    Test_NetGetIPAddr();
    Test_HttpRequest();

    return 0;
}
